package com.czy.owner.adapter;
import android.content.Context;
import android.view.ViewGroup;
import com.czy.owner.entity.MyOrderModel;
import com.czy.owner.ui.workorder.viewholder.OrderCancelledViewHolder;
import com.czy.owner.ui.workorder.viewholder.OrderCommentedViewHolder;
import com.czy.owner.ui.workorder.viewholder.OrderCompletedViewHolder;
import com.czy.owner.ui.workorder.viewholder.OrderCreateViewHolder;
import com.czy.owner.ui.workorder.viewholder.OrderHadPayedViewHolder;
import com.czy.owner.ui.workorder.viewholder.OrderInServiceViewHolder;
import com.czy.owner.ui.workorder.viewholder.OrderInSettlementViewHolder;
import com.czy.owner.ui.workorder.viewholder.OrderWaitPayDepositViewHolder;
import com.czy.owner.ui.workorder.viewholder.OrderWaitServiceViewHolder;
import com.easyrecycleview.adapter.BaseViewHolder;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;


/**
 * Created by wangyang on 2016/6/14.
 */
public class OrderMultiStyleAdapter extends RecyclerArrayAdapter<MyOrderModel> {
    public static final int ORDER_CREATED = 0;
    public static final int ORDER_WAITPAYDEPOSIT = 1;
    public static final int ORDER_WAITSERVICE = 2;
    public static final int ORDER_INSERVICE = 3;
    public static final int ORDER_INSETTLEMENT = 4;
    public static final int ORDER_HASPAYED = 5;
    public static final int ORDER_COMPLETED = 6;
    public static final int ORDER_CANCELLED = 7;
    public static final int ORDER_COMMENTED = 8;
    public static final int DEFAULTERROR = 9;
    //    待处理created,待付定金waitPayDeposit,待服务waitService,服务中inService,结算中inSettlement,已付尾款hasPayed,已完成completed,已取消cancelled，已评价commented
    public static final String CREATED = "created";
    public static final String WAITPAYDEPOSIT = "waitPayDeposit";
    public static final String WAITSERVICE = "waitService";
    public static final String INSERVICE = "inService";
    public static final String INSETTLEMENT = "inSettlement";
    public static final String HASPAYED = "hasPayed";
    public static final String COMPLETED = "completed";
    public static final String CANCELLED = "cancelled";
    public static final String COMMENTED = "commented";
    private Context ctx;

    public OrderMultiStyleAdapter(Context context) {
        super(context);
        this.ctx = context;
    }

    @Override
    public int getViewType(int position) {
        return checkDataType(getItem(position));
    }

    private int checkDataType(MyOrderModel model) {

        if (model.getOrderStatus().equals(CREATED)) {
            return ORDER_CREATED;
        } else if (model.getOrderStatus().equals(WAITPAYDEPOSIT)) {
            return ORDER_WAITPAYDEPOSIT;

        } else if (model.getOrderStatus().equals(WAITSERVICE)) {
            return ORDER_WAITSERVICE;

        } else if (model.getOrderStatus().equals(INSERVICE)) {
            return ORDER_INSERVICE;
        } else if (model.getOrderStatus().equals(INSETTLEMENT)) {
            return ORDER_INSETTLEMENT;

        } else if (model.getOrderStatus().equals(HASPAYED)) {
            return ORDER_HASPAYED;

        } else if (model.getOrderStatus().equals(COMPLETED)) {
            return ORDER_COMPLETED;

        } else if (model.getOrderStatus().equals(CANCELLED)) {
            return ORDER_CANCELLED;

        } else if (model.getOrderStatus().equals(COMMENTED)) {
            return ORDER_COMMENTED;

        }


        return DEFAULTERROR;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        switch (viewType) {
            case ORDER_CREATED:
                return new OrderCreateViewHolder(parent, ctx);
            case ORDER_WAITPAYDEPOSIT:
                return new OrderWaitPayDepositViewHolder(parent, ctx);
            case ORDER_WAITSERVICE:
                return new OrderWaitServiceViewHolder(parent, ctx);
            case ORDER_INSERVICE:
                return new OrderInServiceViewHolder(parent, ctx);
            case ORDER_INSETTLEMENT:
                return new OrderInSettlementViewHolder(parent, ctx);
            case ORDER_HASPAYED:
                return new OrderHadPayedViewHolder(parent, ctx);
            case ORDER_COMPLETED:
                return new OrderCompletedViewHolder(parent, ctx);
            case ORDER_CANCELLED:
                return new OrderCancelledViewHolder(parent, ctx);
            case ORDER_COMMENTED:
                return new OrderCommentedViewHolder(parent, ctx);
            default:
                return new OrderCancelledViewHolder(parent, ctx);
        }
    }
}
